#ifndef __DRAGEVENTRECEIVE_H__
#define __DRAGEVENTRECEIVE_H__

#include "GameGlobal.h"
#include "DragEvent.h"
#include <vector>

typedef void (DragEvent::*SEL_EventHandlerEx)(CCPoint,CCEvent*);
#define event_selectorEx(_SELECTOR) (SEL_EventHandlerEx)(&_SELECTOR)

class DragEventReceive{
private:
	vector<DragEvent*>		*m_touchBeginLayers;
	vector<DragEvent*>		*m_touchMoveLayers;
	vector<DragEvent*>		*m_touchCompleteLayers;

protected:
	virtual void			fireTouchBeginEvent(CCEvent* e);
	virtual void			fireTouchMoveEvent(CCPoint touchPoint,CCEvent* e);
	virtual void			fireTouchEndEvent(CCEvent* e);

public:
	DragEventReceive(void);
	~DragEventReceive(void);

	virtual void			AddTouchEventBeginHandle(DragEvent*);
	virtual void			AddTouchEventMoveHandle(DragEvent*);
	virtual void			AddTouchEventCompleteHandle(DragEvent*);
};

inline DragEventReceive::DragEventReceive( void ){
	m_touchBeginLayers = new vector<DragEvent*>();
	m_touchMoveLayers = new vector<DragEvent*>();
	m_touchCompleteLayers = new vector<DragEvent*>();
}

inline DragEventReceive::~DragEventReceive( void )
{
	delete m_touchBeginLayers;
	delete m_touchMoveLayers;
	delete m_touchCompleteLayers;
}

inline void DragEventReceive::fireTouchBeginEvent( CCEvent* e )
{
	if(m_touchBeginLayers){
		vector<DragEvent*>::iterator it; 
		for (it = m_touchBeginLayers->begin(); it != m_touchBeginLayers->end(); it++) 
		{ 
			(*it)->touchBeginHandler(e);
		}
	}
}

inline void DragEventReceive::fireTouchMoveEvent(CCPoint touchPoint, CCEvent* e )
{
	if(m_touchMoveLayers){
		vector<DragEvent*>::iterator it; 
		for (it = m_touchMoveLayers->begin(); it != m_touchMoveLayers->end(); it++) 
		{ 
			(*it)->touchMoveHandler(touchPoint,e);
		}
	}
}

inline void DragEventReceive::fireTouchEndEvent( CCEvent* e )
{
	if(m_touchCompleteLayers){
		vector<DragEvent*>::iterator it; 
		for (it = m_touchCompleteLayers->begin(); it != m_touchCompleteLayers->end(); it++) 
		{ 
			(*it)->touchCompleteHandler(e);
		}
	}
}

inline void DragEventReceive::AddTouchEventBeginHandle( DragEvent* e )
{
	m_touchBeginLayers->push_back(e);
}

inline void DragEventReceive::AddTouchEventMoveHandle( DragEvent* e )
{
	m_touchMoveLayers->push_back(e);
}

inline void DragEventReceive::AddTouchEventCompleteHandle( DragEvent* e )
{
	m_touchCompleteLayers->push_back(e);
}

#endif